<?php

namespace console\controllers;

use services\hiss\DataMigrateService;
use Yii;
use yii\console\Controller;
use Exception;

/**
 * 迁移hiss数据
 *
 * Class MsgHistoryController
 * @package console\controllers
 */
class DataMigrateController extends Controller
{

    /**
     * 同步员工
     *
     * @author wangxiang
     * @param int $projectId    项目id
     */
    public function actionUser(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::user($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }


    /**
     * 更新患者信息
     *
     * @author wangxiang
     * @param int $projectId
     */
    public function actionPatient(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::patient($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }


    /**
     * 修复脚本信息
     *
     * @author wangxiang
     * @param int $projectId
     */
    public function actionRepairPatient(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::repairPatient($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    /**
     * 查找手机号不相同的信息
     *
     * @author wangxiang
     * @param int $projectId
     */
    public function actionTel(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::tel($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    /**
     * 修改手机号
     *
     * @author wangxiang
     * @param int $projectId
     */
    public function actionChangeTel(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::changeTel($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    public function actionTest(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::test($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    public function actionChangeData(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::changeData($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    public function actionChangeCs()
    {
        try {
            $startTime = time();
            DataMigrateService::changeCs();
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }


    public function actionRepairCallbackInfo()
    {
        try {
            $startTime = time();
            $errorPatientIdData = DataMigrateService::repairCallbackInfo();
            print_r($errorPatientIdData);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }

    /**
     * 海口项目数据从hiss迁移到白友
     *
     * @author chenyuebin
     * @param int $projectId
     */
    public function actionHissToBy(int $projectId)
    {
        try {
            $startTime = time();
            DataMigrateService::hissToBy($projectId);
            echo time() - $startTime . '==success!';
        } catch (Exception $exception) {
            echo 'error:' . $exception;
        }
    }
}
